package com.jhhc.StormSurgeForecast.StormSurge;
import com.alibaba.fastjson2.JSONObject;

import com.jhhc.StormSurgeForecast.AstronomicalTide.Pojo.BDMS_CALCULATESCHEME_M1;
import com.jhhc.StormSurgeForecast.AstronomicalTide.Service.BDMS_CALCULATESCHEME_MService;
import com.jhhc.StormSurgeForecast.AstronomicalTide.Service.BDMS_FBC_RESULT_PService;
import com.jhhc.StormSurgeForecast.AstronomicalTide.Util.GetSeaWallUitl;
import com.jhhc.StormSurgeForecast.StormSurge.Pojo.*;

import com.jhhc.StormSurgeForecast.StormSurge.Pojo.Dto.UpdateTideData;
import com.jhhc.StormSurgeForecast.StormSurge.Pojo.Dto.UpdateTideDataParam;
import com.jhhc.StormSurgeForecast.StormSurge.Pojo.FBC.BDMS_FBC_GRID_F;
import com.jhhc.StormSurgeForecast.StormSurge.Pojo.FBC.BDMS_FBC_OCEANMODEL_B;
import com.jhhc.StormSurgeForecast.StormSurge.Pojo.FBC.BDMS_FBC_RESULT_SCHEME;
import com.jhhc.StormSurgeForecast.StormSurge.Pojo.GZABO.*;
import com.jhhc.StormSurgeForecast.StormSurge.Pojo.Param.GridParam;
import com.jhhc.StormSurgeForecast.StormSurge.Pojo.Product.ProductInfoResult;
import com.jhhc.StormSurgeForecast.StormSurge.Pojo.ZJBO.SeaWall;
import com.jhhc.StormSurgeForecast.StormSurge.Service.*;
import com.jhhc.StormSurgeForecast.StormSurge.Uitl.*;
import com.jhhc.utils.JsonResult;
import com.jhhc.utils.StationForeCastTideResult;
import com.jhhc.utils.ToTimeUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.PropertySource;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


import java.io.IOException;
import java.text.DecimalFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

@Api(value="StormSurgeController",tags={"风暴潮相关服务"})
@RequestMapping(value = "StormSurgeForecast",headers = "Accept=application/json")
@RestController
@PropertySource(value="classpath:application.yml",encoding = "UTF-8")
public class StormSurgeController {
    @Autowired
    private GetTyphoonUitl getTyphoonUitl;
    @Autowired
    private GetSeaWallUitl getSeaWallUitl;
    @Autowired
    private BDMS_FBC_ELEMENTS_BService bdms_fbc_elements_bService;
    @Autowired
    private BDMS_FBC_RESULT_AService bdms_fbc_result_aService;
    @Autowired
    private BDMS_FBC_OCEANMODEL_BService bdms_fbc_oceanmodel_bService;
    @Autowired
    private BDMS_FBC_ASTROTD_AService bdms_fbc_astrotd_aService;
    @Autowired
    private BDMS_CALCULATESCHEME_MService bdms_calculatescheme_mService;
    @Autowired
    private BDMS_FBC_GRID_FService bdms_fbc_grid_fService;
    @Autowired
    private BDMS_FBC_RESULT_SService bdms_fbc_result_sService;
    @Autowired
    private GetDataUtil getDataUtil;
    @Autowired
    private BDMS_FBC_RESULT_PService pService;

    //添加不输入台风id
    //更改顺序
    //天文潮报表服务
    DecimalFormat df = new DecimalFormat("0.00");
    //老库
    //添加计算方案时间范围  布尔  (未完成)
    //添加参数 已发布的最新一条 FLAG  boolean
    @ApiOperation("获取预报计算方案列表")
    @RequestMapping(value = "StormSurge/Calculate/GetCalSchemeInfos", headers = "Accept=application/json", method = RequestMethod.GET)
    public JsonResult GetCalSchemeInfoByTyphoonIds( @RequestParam int ProjectId, @RequestParam(required = false) Integer TyphoonId,
                        @RequestParam(required = false) String StartTime, @RequestParam(required = false) String EndTime,@RequestParam(required = false) Boolean IsForecastTime
    ,  @RequestParam(required = false) Integer DBType,@RequestParam(required = false)  String ModelID,@RequestParam(required = false) Boolean IsPublished ,@RequestParam(required = false) String Status,
                                                    @RequestParam(required = false) String Forecaster,@RequestParam(required = false) String Path,
                                                    @RequestParam(required = false) String Flag){
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar calendar = new GregorianCalendar();
        JsonResult jsonResult = new JsonResult();
        if (IsForecastTime==null){
            IsForecastTime =true;
        }
        if(DBType==null){
            DBType =0;
        }
        if (IsPublished==null){
            IsPublished =true;
        }
        if ("y".equals(Flag)){
            Flag ="y";
        }else {
            Flag =null;
        }

//        System.out.println(StartTime);
//        System.out.println(EndTime);


        List<CalSchemeInfo> calSchemeInfos  = new ArrayList<>();
        if (IsForecastTime){
            if (DBType ==1){
                   List<BDMS_FBC_RESULT_SCHEME> bdms_fbc_result_schemeList= getTyphoonUitl.getBdms_fbc_result_scheme(ProjectId, TyphoonId, StartTime, EndTime, Integer.valueOf(ModelID),IsPublished);
                   for (BDMS_FBC_RESULT_SCHEME bdms_fbc_result_scheme:bdms_fbc_result_schemeList){
                       CalSchemeInfo calSchemeInfo = new CalSchemeInfo();
                       calSchemeInfo.setCalSchemeId(String.valueOf(bdms_fbc_result_scheme.getSchemeId()));
                       calSchemeInfo.setTyphoonId(String.valueOf(bdms_fbc_result_scheme.getTfid()));
                       calSchemeInfo.setForecastTime(bdms_fbc_result_scheme.getYmdhm());
                       try {
                           Date ForecastEndTM = format.parse(bdms_fbc_result_scheme.getYmdhm());
                           calendar.setTime(ForecastEndTM);
                           calendar.add(Calendar.HOUR,+bdms_fbc_result_scheme.getCalnum());
                           calSchemeInfo.setForecastEndTime(format.format(calendar.getTime()));
                       }catch (Exception e){
                           e.printStackTrace();
                       }
                       calSchemeInfo.setUserId(String.valueOf(bdms_fbc_result_scheme.getUserId()));
                       calSchemeInfo.setModelId(String.valueOf(bdms_fbc_result_scheme.getModelId()));
                       calSchemeInfo.setTyphoonId(String.valueOf(bdms_fbc_result_scheme.getTfid()));
                       calSchemeInfo.setTyphoonDepart(bdms_fbc_result_scheme.getReportDept());
                       calSchemeInfo.setState(String.valueOf(bdms_fbc_result_scheme.getState()));
                       calSchemeInfo.setModelPar(String.valueOf(bdms_fbc_result_scheme.getExpparam()));
                       calSchemeInfo.setRemark("state 0 新建方案、1 计算中、2 计算失败、3 计算成功");
                       if (bdms_fbc_result_scheme.getFlag()!=null){
                           calSchemeInfo.setHasArea("1");
                           calSchemeInfo.setHasPublish(1);
                       }
                       calSchemeInfo.setCalSchemeName(bdms_fbc_result_scheme.getYmdhm().substring(5,16)
                               +","+bdms_fbc_result_scheme.getReportDept()+","+calSchemeInfo.getModelPar());

                       calSchemeInfo.setFlag(String.valueOf(bdms_fbc_result_scheme.getFlag()));

                       calSchemeInfos.add(calSchemeInfo);
                   }
               }else if(DBType == 0){
                String res =null;
                if (IsPublished){
                    res ="";
                }
                String tfid;
               if (TyphoonId!=null){
                   tfid =String.valueOf(TyphoonId);
               }else {
                   tfid="";
               }
                if (Status==null|| "".equals(Status)){
                    Status ="预报";
                }
                //System.out.println(Status);
                List<BDMS_CALCULATESCHEME_M1> bdms_calculatescheme_ms = bdms_calculatescheme_mService.selectShcemeByPidDate(ProjectId,tfid,StartTime,EndTime,res,Status,Forecaster,Path,Flag,ModelID);
                bdms_calculatescheme_ms.sort(Comparator.comparing(BDMS_CALCULATESCHEME_M1::getDtmcalculate));
                int i=0;
                for (BDMS_CALCULATESCHEME_M1 bdms_calculatescheme_m:bdms_calculatescheme_ms){
                    CalSchemeInfo calSchemeInfo  =new CalSchemeInfo();
                    if (bdms_calculatescheme_m != null) {
                        if (bdms_calculatescheme_m.getParams()!=null){
                            String [] a;
                            a= bdms_calculatescheme_m.getParams().split(",");
                            calSchemeInfo.setTyphoonId(a[0]);
                            calSchemeInfo.setTyphoonDepart(a[1]);
                            calSchemeInfo.setModelPar(df.format(Double.valueOf(a[2])));
                        }
                        i +=1;
                        calSchemeInfo.setCalSchemeId(bdms_calculatescheme_m.getCschemeid());

                        calSchemeInfo.setUserId(bdms_calculatescheme_m.getUserid());
                        //根据modelid获取model名称
                        BDMS_FBC_OCEANMODEL_B bdms_fbc_oceanmodel_b =bdms_fbc_oceanmodel_bService.getModelInfoByModelId(ProjectId,bdms_calculatescheme_m.getMdid());
                       if (bdms_fbc_oceanmodel_b!=null){
                           calSchemeInfo.setModelId(bdms_fbc_oceanmodel_b.getModelid());
                           calSchemeInfo.setModelName(bdms_fbc_oceanmodel_b.getModelnm());
                       }
                        calSchemeInfo.setForecastOperateTime(bdms_calculatescheme_m.getDtmcalculate());
                        calSchemeInfo.setForecastEndTime(bdms_calculatescheme_m.getDtmend());
                        calSchemeInfo.setUserName("预报员");
                        calSchemeInfo.setForecastTime(bdms_calculatescheme_m.getDtmforecast());
                        calSchemeInfo.setState(String.valueOf(bdms_calculatescheme_m.getState()));
                        calSchemeInfo.setHasGen(bdms_calculatescheme_m.getIsgen());
                        calSchemeInfo.setFlag(bdms_calculatescheme_m.getFlag());
                        calSchemeInfo.setState(bdms_calculatescheme_m.getState());
                        calSchemeInfo.setRemark("state 0 新建方案、1 计算中、2 计算失败、3 计算成功");
                        calSchemeInfo.setHasArea(bdms_calculatescheme_m.getIsarea());
                        calSchemeInfo.setHasPublish(bdms_calculatescheme_m.getPublish());
                        calSchemeInfo.setCalSchemeName(bdms_calculatescheme_m.getCschemenm());
                        if (StartTime!=null && EndTime!=null){
                            if (StartTime.equals(EndTime)){
                                String a ="";
                                if (calSchemeInfo.getHasArea()!=null&& !"0".equals(calSchemeInfo.getHasArea())){
                                  a=  ",A"+calSchemeInfo.getHasArea();
                                }
                                calSchemeInfo.setCalSchemeName("方案"+i+","+bdms_calculatescheme_m.getDtmforecast().substring(5,16)
                                        +","+bdms_calculatescheme_m.getFschemeid()+","+calSchemeInfo.getModelName()+","+calSchemeInfo.getModelPar()+a);

                                bdms_calculatescheme_m.setCschemenm("方案"+i);
                                bdms_calculatescheme_mService.saveCalSchemeInfo(bdms_calculatescheme_m);
                            }
                        }
                    }
                    calSchemeInfos.add(calSchemeInfo);
                }
            }
        }
        jsonResult.setSucceeded(true);
        jsonResult.setStatusCode(200);
        if (calSchemeInfos.size()>0){
            jsonResult.setData(calSchemeInfos);
        }else {
            jsonResult.setData("未查询到相关计算方案信息");
        }

        return  jsonResult;
    }
    //删除计算方案id
    @ApiOperation("删除计算方案")
    @RequestMapping(value = "StormSurge/Calculate/DeleteCalScheme", headers = "Accept=application/json", method = RequestMethod.GET)
    public JsonResult getCalResults( @RequestParam List<String> calSchemeIds){
        JsonResult jsonResult = new JsonResult();
      int  res = bdms_calculatescheme_mService.deleteCalById(calSchemeIds);
        if (res>0){
            jsonResult.setData("删除成功");
            jsonResult.setSucceeded(true);
            jsonResult.setStatusCode(200);
        }else {
            jsonResult.setData("删除失败");
            jsonResult.setSucceeded(true);
            jsonResult.setStatusCode(500);
        }
        return  jsonResult;
    }
    //默认新库 0 老库1  接口参数不输入为0
    //
    //天文潮报表服务
    @ApiOperation("获取多个预报方案的预报站点结果")
    @RequestMapping(value = "StormSurge/Calculate/GetCalResultsByStations", headers = "Accept=application/json", method = RequestMethod.GET)
    public JsonResult GetCalResultsByStations( @RequestParam int ProjectId,
                                     @RequestParam List<String> CalSchemeIds, @RequestParam(required = false) List<String> StationCodes,
                                     @RequestParam(required = false) Integer TwcDept,  @RequestParam(required = false) Integer BackDays, @RequestParam(required = false) Integer DBType
            ,@RequestParam(required = false) Integer StepLength) throws IOException, ParseException {
        JsonResult jsonResult = new JsonResult();
        jsonResult.setStatusCode(200);
        jsonResult.setSucceeded(true);
        if (TwcDept==null){
            TwcDept =0;
        }
        if (BackDays==null){
            BackDays=0;
        }
        if (DBType==null){
            DBType=0;
        }
        jsonResult.setData(getTyphoonUitl.getBdms_fbc_result2(ProjectId,
                CalSchemeIds,StationCodes,TwcDept, BackDays,DBType,StepLength));
        return jsonResult;
    }
    //天文潮报表服务
    @ApiOperation("获取预报站点预报计算结果GetCalResultsByStation")
    @RequestMapping(value = "StormSurge/Calculate/GetCalResultsByStationNew", headers = "Accept=application/json", method = RequestMethod.GET)
    public JsonResult getCalResults( @RequestParam int ProjectId, @RequestParam String CalSchemeId,
                                     @RequestParam(required = false) List<String> StationCodes,
                                     @RequestParam(required = false) Integer TwcDept,  @RequestParam(required = false) Integer BackDays, @RequestParam(required = false) Integer DBType
            ,@RequestParam(required = false) Integer StepLength) throws IOException, ParseException {
        JsonResult jsonResult = new JsonResult();
        jsonResult.setStatusCode(200);
        jsonResult.setSucceeded(true);
        if (TwcDept==null){TwcDept =0;}
        if (BackDays==null){BackDays=0;}
        if (DBType==null){DBType=0;}
        if (StepLength==null){StepLength=60;}
        List<String> list = new ArrayList<>();
        list.add(CalSchemeId);
        jsonResult.setData(getDataUtil.getDataByCalSchemeIdStationcodes(ProjectId,list,
                StationCodes,TwcDept,BackDays,StepLength,DBType));

        return jsonResult;
    }
    @ApiOperation("test获取多个预报方案的预报站点结果")
    @RequestMapping(value = "StormSurge/Calculate/GetCalResultsByStationT", headers = "Accept=application/json", method = RequestMethod.GET)
    public JsonResult GetCalResultsByStations55( @RequestParam int ProjectId,
                                               @RequestParam String CalSchemeId, @RequestParam(required = false) List<String> StationCodes,
                                               @RequestParam(required = false) Integer TwcDept,  @RequestParam(required = false) Integer BackDays, @RequestParam(required = false) Integer DBType
            ,@RequestParam(required = false) Integer StepLength) throws IOException, ParseException {
        JsonResult jsonResult = new JsonResult();
        jsonResult.setStatusCode(200);
        jsonResult.setSucceeded(true);
        if (TwcDept==null){
            TwcDept =0;
        }
        if (BackDays==null){
            BackDays=0;
        }
        if (DBType==null){
            DBType=0;
        }
        if (StepLength==null){
            StepLength =60 ;
        }
        jsonResult.setData(getTyphoonUitl.getBdms_fbc_result(ProjectId,
                CalSchemeId,StationCodes,TwcDept, BackDays,DBType,StepLength));
        return jsonResult;
    }
    @ApiOperation("2222获取多个预报方案的预报站点结果")
    @RequestMapping(value = "StormSurge/Calculate/GetCalResultsByStation", headers = "Accept=application/json", method = RequestMethod.POST)
    public JsonResult GetCalResultsByStation( @RequestBody JSONObject jsonObject) throws IOException, ParseException {
         Integer projectId = jsonObject.getInteger("projectId");
         List<String> calSchemeIds =jsonObject.getList("calSchemeIds",String.class);
        JsonResult jsonResult = new JsonResult();
         if (calSchemeIds.size()>0){
             String stationCode = jsonObject.getString("stationCode");
             Integer twcDept =  jsonObject.getInteger("twcDept");
             Integer backDays =  jsonObject.getInteger("backDays");
             Integer stepLength =jsonObject.getInteger("stepLength");
             if (stepLength==null){
                 stepLength=60;
             }
             Integer DBtype =jsonObject.getInteger("DBType");

             jsonResult.setStatusCode(200);
             jsonResult.setSucceeded(true);
             if (twcDept==null){
                 twcDept =0;
             }
             if (backDays==null){
                 backDays=0;
             }
             if (DBtype==null){
                 DBtype=0;
             }
             com.jhhc.utils.CalResult calResult =getDataUtil.getDataByCalSchemeIds(projectId,
                     calSchemeIds,stationCode,twcDept, backDays,stepLength,DBtype);
             if (calResult!=null){
                 jsonResult.setData(calResult);
                 if (calResult.getStationCode()==null){
                     jsonResult.setRemark("无此站点的预报信息");
                 }else {
                     jsonResult.setRemark("请求成功");
                 }
             }
         }else {
             jsonResult.setStatusCode(200);
             jsonResult.setSucceeded(true);
             jsonResult.setData(null);
             jsonResult.setRemark("当前未输入计算方案编号，请检查参数");
         }



        return jsonResult;
    }

    @ApiOperation("3333获取多个预报方案的预报站点结果")
    @RequestMapping(value = "StormSurge/Calculate/GetCalResultsByStations3", headers = "Accept=application/json", method = RequestMethod.POST)
    public JsonResult GetCalResultsByStationss3( @RequestBody JSONObject jsonObject) throws IOException, ParseException {
        Integer projectId = jsonObject.getInteger("projectId");
        List<String> stationCodes =jsonObject.getList("stationCodes",String.class);
        String  calSchemeId= jsonObject.getString("calSchemeId");
        Integer twcDept =  jsonObject.getInteger("twcDept");
        Integer backDays =  jsonObject.getInteger("backDays");

        JsonResult jsonResult = new JsonResult();
        jsonResult.setStatusCode(200);
        jsonResult.setSucceeded(true);
        if (twcDept==null){
            twcDept =0;
        }
        if (backDays==null){
            backDays=0;
        }
        jsonResult.setData(getDataUtil.getDataByCalSchemeIds3(projectId,
                calSchemeId,stationCodes,twcDept, backDays));
        jsonResult.setRemark("请求成功");
        return jsonResult;
    }
    //
    //查询堤防基础信息
    //获取堤防信息
    @ApiOperation("获取堤防信息")
    @RequestMapping(value = "StormSurge/BaseInfo/GetSeaWallInfo", headers = "Accept=application/json", method = RequestMethod.GET)
    public JsonResult getSeaWallInfo( @RequestParam int ProjectId, @RequestParam(required = false) Integer SeaWallId){
        JsonResult jsonResult = new JsonResult();
        jsonResult.setStatusCode(200);
        jsonResult.setSucceeded(true);
        jsonResult.setData(getSeaWallUitl.getSeaWallInfo(ProjectId));
        return  jsonResult;
    }

    //获取最新一条预报方案
    @ApiOperation("获取最新一条预报计算方案")
    @RequestMapping(value = "StormSurge/Calculate/GetNewestCalSchemeInfo", headers = "Accept=application/json", method = RequestMethod.GET)
    public JsonResult getNewestCalSchemeInfo(@RequestParam(required = false) Integer ProjectId, @RequestParam(required = false) Integer TyphoonId,
                                             @RequestParam(required = false) String ForecastTime,@RequestParam String ModelId,@RequestParam(required = false) Integer DBType,
                                             @RequestParam(required = false) String  area){
        JsonResult jsonResult = new JsonResult();
        jsonResult.setStatusCode(200);
        jsonResult.setSucceeded(true);

        jsonResult.setData(getTyphoonUitl.getNewestCalSchemeInfo(ProjectId,TyphoonId,ForecastTime,ModelId,DBType,area));
        return jsonResult;
    }
    //获取最新一条预报方案
    @ApiOperation("获取预报格点的计算结果")
    @RequestMapping(value = "StormSurge/Calculate/GetCalResultsByGrid", headers = "Accept=application/json", method = RequestMethod.GET)
    public JsonResult getCalResultsByGrid(@RequestParam Integer ProjectId,@RequestParam Integer CalSchemeId,@RequestParam String AreaName,
                                        @RequestParam List<Integer> GridIds ,@RequestParam Integer Dttp,@RequestParam(required = false) Boolean IsAstronomical){
        JsonResult jsonResult = new JsonResult();
        jsonResult.setStatusCode(200);
        jsonResult.setSucceeded(true);
        jsonResult.setData(getTyphoonUitl.getCalResultsByGrid(ProjectId,CalSchemeId,AreaName,Dttp,GridIds,IsAstronomical));
        return jsonResult;
    }

    @ApiOperation("获取预报格点的计算结果22")
    @RequestMapping(value = "StormSurge/Calculate/GetCalResultsByGrid2", headers = "Accept=application/json", method = RequestMethod.POST)
    public JsonResult getCalResultsByGrid2(@RequestBody GridParam gridParam){
        JsonResult jsonResult = new JsonResult();
        jsonResult.setStatusCode(200);
        jsonResult.setSucceeded(true);
        jsonResult.setData(getTyphoonUitl.getCalResultsByGrid2(gridParam));
        return jsonResult;
    }

    /**
     *获取模型计算域信息
     * @param projectId
     * @param elementName
     *@RequestParam(required = false) Integer grids,
     *@RequestParam(required = false) boolean Dilute
     * @return
     */
    @ApiOperation("获取模型计算域信息")
    @RequestMapping(value = "StormSurge/BaseInfo/GetCalDomainInfo", headers = "Accept=application/json", method = RequestMethod.GET)
    public JsonResult getCalDomainInfo(@RequestParam Integer projectId,@RequestParam String elementName,
                                       @RequestParam(required = false) String type){
        JsonResult jsonResult = new JsonResult();
        jsonResult.setStatusCode(200);
        jsonResult.setSucceeded(true);
        Element element = null;
        if ("2".equals(type)) {
            element = bdms_fbc_elements_bService.GetCalDomainInfo(projectId, elementName, type);
        }else {
            element = bdms_fbc_elements_bService.GetCalDomainInfo(projectId,elementName);
        }

//        if (grids != null && grids != 0) {
//            element = bdms_fbc_elements_bService.GetCalDomainInfo(ProjectId, ElementNm, grids);
//        }else {
//            element = bdms_fbc_elements_bService.GetCalDomainInfo(ProjectId,ElementNm);
//        }
        if (element != null) {
            jsonResult.setData(element);
            jsonResult.setRemark("获取成功");
        }else {
            jsonResult.setRemark("获取失败，该项目编号模型计算域信息为空");
        }

        return jsonResult;
    }
    /**
     * 获取模型中心点信息
     * @param projectId
     * @param elementName
     * @RequestParam(required = false) Integer grids,
     * @RequestParam(required = false) boolean Dilute
     * @return
     */
    @ApiOperation("获取模型中心点信息")
    @RequestMapping(value = "StormSurge/BaseInfo/GetCalCentreInfo", headers = "Accept=application/json", method = RequestMethod.GET)
    public JsonResult getCalCentreInfo(@RequestParam Integer projectId,@RequestParam String elementName){
        JsonResult jsonResult = new JsonResult();
        Center center = bdms_fbc_elements_bService.GetCalCentreInfo(projectId,elementName);
//        if (grids != null) {
//            center = bdms_fbc_elements_bService.GetCalCentreInfo(ProjectId, ElementNm, grids);
//        }else {
//            center = bdms_fbc_elements_bService.GetCalCentreInfo(ProjectId,ElementNm);
//        }
        if (center != null) {
            jsonResult.setStatusCode(200);
            jsonResult.setSucceeded(true);
            jsonResult.setData(center);
        }else {
            jsonResult.setStatusCode(200);
            jsonResult.setSucceeded(true);
            jsonResult.setRemark("该项目编号模型中心点信息为空");
        }
        return jsonResult;
    }
    //根据方案编号获取计算方案信息
    @ApiOperation("根据方案编号获取计算方案信息")
    @RequestMapping(value = "StormSurge/Calculate/GetCalSchemeInfoByCalSchemeId", headers = "Accept=application/json", method = RequestMethod.GET)
    public  JsonResult getCalSchemeInfoByCalSchemeId( @RequestParam(required = false) String calSchemeId,@RequestParam(required = false) Integer DBType){
        JsonResult jsonResult = new JsonResult();
        jsonResult.setStatusCode(200);
        jsonResult.setSucceeded(true);
        jsonResult.setData(getTyphoonUitl.getCalSchemeInfoByCalSchemeId(calSchemeId,DBType));
        return jsonResult;
    }
    //获取站点潮位
    @ApiOperation("获取站点潮位数据")
    @RequestMapping(value = "StormSurge/Calculate/GetStationTide", headers = "Accept=application/json", method = RequestMethod.GET)
    public  JsonResult getStationTide( @RequestParam int ProjectId, @RequestParam List<String> StationCodes,
                                       @RequestParam String StartTime,@RequestParam String EndTime  ,@RequestParam(required = false) Integer StepLength){

        JsonResult jsonResult = new JsonResult();
        System.out.println(StationCodes);
        jsonResult.setStatusCode(200);
        jsonResult.setSucceeded(true);
        jsonResult.setData(getTyphoonUitl.getStationTideData(ProjectId, StationCodes, StartTime, EndTime,StepLength));
        return jsonResult;
    }

    @Autowired
    private ToTimeUtil toTimeUtil;
    @ApiOperation("222222222获取站点潮位数据")
    @RequestMapping(value = "StormSurge/Calculate/GetStationForecastTide", headers = "Accept=application/json", method = RequestMethod.GET)
    public  JsonResult getStationTide2222(@RequestParam(required = false) Integer projectId, @RequestParam List<String> stationCodes,
                                          @RequestParam String startTime, @RequestParam String endTime  ,
                                          @RequestParam(required = false) Integer stepLength,
                                          @RequestParam(required = false) String modelId,Integer DBType ) throws ParseException {

        JsonResult jsonResult = new JsonResult();
        //根据开始时间结束时间站码集合 去库里查询对应的天文潮数据
        jsonResult.setStatusCode(200);
        jsonResult.setSucceeded(true);
        if (DBType==null){
            DBType=0;
        }
        if (stepLength==null){
            stepLength=60;
        }
        LocalDateTime dateTime1 = toTimeUtil.getDateTime(startTime);
        LocalDateTime dateTime2 = toTimeUtil.getDateTime(endTime);
        if (dateTime1.compareTo(dateTime2) <= 0) {
            List<StationForeCastTideResult> tides = getDataUtil.getStationForecastTide(projectId, startTime, endTime, stationCodes, stepLength, modelId, DBType);
            if (tides.size()>0){
                jsonResult.setData(tides);
                jsonResult.setRemark("请求成功");
            }else {
                jsonResult.setRemark("未查询到此站点该时间段内的数据");
            }
        } else  {
            jsonResult.setRemark("开始时间大于结束时间，请更换参数值");
        }
        //jsonResult.setData(getDataUtil.getStationForecastTide(projectId, startTime, endTime, stationCodes, stepLength, modelId, DBType));

        return jsonResult;
    }
    //获取预报场的计算结果
    @ApiOperation("获取预报场的计算结果")
    @RequestMapping(value = "StormSurge/Calculate/GetCalResultsByDomain", headers = "Accept=application/json", method = RequestMethod.GET)
    public JsonResult getCalResultsByDomain(@RequestParam String calSchemeId,
                                            @RequestParam(required = false) String startTime,
                                            @RequestParam(required = false) String endTime,
                                            @RequestParam Integer dttp,
                                            @RequestParam(required = false) Boolean astronomical,
                                            @RequestParam(required = false) Integer projectId,
                                            @RequestParam(defaultValue = "true") boolean isData) {
        JsonResult jsonResult = new JsonResult();
        jsonResult.setStatusCode(200);
        jsonResult.setSucceeded(true);
        BDMS_CALCULATESCHEME_M1 bdmsCalculateschemeM1 =
                bdms_calculatescheme_mService.selcalSchemeId(calSchemeId);
        if (bdmsCalculateschemeM1 != null) {
            if (bdmsCalculateschemeM1.getIsarea() != null && "2".equals(bdmsCalculateschemeM1.getIsarea())) {
                if (astronomical != null && astronomical && projectId != null) {
                    List<Float[]> astronomicals = bdms_fbc_astrotd_aService.
                            GetAstronomical(Integer.valueOf(calSchemeId),startTime,endTime);
                    List<int[]> waterIncrementValues = bdms_fbc_result_aService.
                            GetCalResultsByDomain1(calSchemeId, startTime,endTime, dttp);
                    List<Float[]> floats = new ArrayList<>();
                    if (astronomicals.size() > 0) {
                        for (int i = 0; i < astronomicals.size(); i++) {
                            List<Float> forecastTideLevels = new ArrayList<>();
                            for (int j = 0; j < astronomicals.get(i).length; j++) {
                                int waterIncrementValue = waterIncrementValues.get(i)[j] / JudgeUtil.isMultiple(dttp);
                                float f = 0;
                                if (astronomicals.get(i)[j] != -88888888) {
                                    f = astronomicals.get(i)[j];
                                }
                                float forecastTideLevel = waterIncrementValue + f;
                                forecastTideLevels.add(forecastTideLevel);
                            }
                            Float[] f = forecastTideLevels.toArray(new Float[0]);
                            floats.add(f);
                        }
                        jsonResult.setData(floats);
                    }else {
                        jsonResult.setRemark("该计算方案在" + startTime + "——" + endTime + "时间段内综合潮位数据为空");
                    }
                    return jsonResult;
                }else {
                    Result result = bdms_fbc_result_aService.
                            GetCalResultsByDomain(calSchemeId, startTime,endTime, dttp,isData);
                    if (result != null) {
                        jsonResult.setData(result);
                    }else {
                        jsonResult.setRemark("该计算方案在" + startTime + "——" + endTime + "时间段内信息为空");
                    }
                }
            }else if (bdmsCalculateschemeM1.getIsarea() != null && "1".equals(bdmsCalculateschemeM1.getIsarea())){
                jsonResult.setRemark("该方案预报场数未入库，可调用保存预报场结果的接口等待5分钟即可成功获取预报场数据");
            }else if (bdmsCalculateschemeM1.getIsarea() != null && "3".equals(bdmsCalculateschemeM1.getIsarea())) {
                jsonResult.setRemark("保存预报场数据失败");
            }else {
                jsonResult.setRemark("该计算方案无预报场数据");
            }
        }else {
            jsonResult.setRemark("未找到该计算方案");
        }
        return jsonResult;
    }

    //查询告警接口
    @ApiOperation("获取告警状态接口")
    @RequestMapping(value = "StormSurge/GetAlarmData", headers = "Accept=application/json", method = RequestMethod.GET)
    public JsonResult getAlarmData(@RequestParam Integer ProjectId, @RequestParam List<String> StationCodes, @RequestParam(required = false) Integer DBType){
        JsonResult jsonResult = new JsonResult();
        jsonResult.setStatusCode(200);
        jsonResult.setSucceeded(true);
        if (DBType==null){
            DBType=0;
        }
        List<Alarm> alarms = getTyphoonUitl.getNewDataN(ProjectId,StationCodes,DBType);
        if (alarms.size()>0){
            jsonResult.setData(alarms);
        }else {
            jsonResult.setRemark("未查询到相关数据");
        }


        return jsonResult;
    }

    //获取预报模型列表
    @ApiOperation("获取预报模型列表")
    @RequestMapping(value = "StormSurge/Calculate/GetModelInfos", headers = "Accept=application/json", method = RequestMethod.GET)
    public JsonResult getModelInfos(@RequestParam(required = false) Integer ProjectId,@RequestParam List<ModelTypeEnum> ModelTypes){
        JsonResult jsonResult = new JsonResult();

        try {
            List<String> modelTps = new ArrayList<>();
            for (ModelTypeEnum modelType:ModelTypes){
                modelTps.add(modelType.toString());
            }

            jsonResult.setStatusCode(200);
            jsonResult.setSucceeded(true);
            jsonResult.setData(getTyphoonUitl.getModelInfos(ProjectId,modelTps));
        } catch (Exception e ) {
            // 发生异常时，返回相应的错误状态码
            jsonResult.setData(ResponseEntity.status(HttpStatus.BAD_REQUEST).body("请检查参数是否正确"));

//            if (statusCode == 400) {
//                // 处理400错误的逻辑
//                jsonResult.setStatusCode(200);
//                jsonResult.setSucceeded(true);
//                jsonResult.setData("请检查接口参数是否正确");
//            } else if (statusCode == 500) {
//                // 处理500错误的逻辑
//                System.out.println("捕获到500错误");
//            } else {
//                // 处理其他错误的逻辑
//                System.out.println("捕获到其他错误");
//            }

        }
        return jsonResult;
    }

    //dttp 桥墩  填充岛屿  沉管
    @ApiOperation("获取港珠澳大桥特征信息列表")
    @RequestMapping(value = "StormSurge/Calculate/GetBasicInfoList",headers = "Accept=application/json",method = RequestMethod.GET)
    public JsonResult getBasicInfoList(@RequestParam(value = "dttp")String dttp){
        JsonResult jsonResult = new JsonResult();
        List<FeaturesInfo> strings = bdms_fbc_grid_fService.getBasicInfoList(dttp);
        if (strings.size() > 0) {
            jsonResult.setStatusCode(200);
            jsonResult.setSucceeded(true);
            jsonResult.setData(strings);
        }else {
            jsonResult.setStatusCode(200);
            jsonResult.setSucceeded(true);
            jsonResult.setData(dttp + "该类型查询无数据");
        }
        return jsonResult;
    }

    @ApiOperation("获取港珠澳大桥计算结果列表")//港珠澳大桥
    @RequestMapping(value = "StormSurge/Calculate/GetCalculationResultsList",headers = "Accept=application/json",method = RequestMethod.GET)
    public JsonResult getCalculationResultsList(@RequestParam(value = "CSCHEMEID")String CSCHEMEID,
                                            @RequestParam(value = "dtnm")String dtnm, //特征名称
                                            @RequestParam("StartTime")String StartTime,//开始时间
                                            @RequestParam("EndTime")String EndTime,//结束时间
                                            @RequestParam("rule")boolean rule){//模式：true波流 false水流
        //,@RequestParam(required = false,value = "typeofpier")String typeofpier,//特征类型
        JsonResult jsonResult = new JsonResult();
       // String dttp = JudgeUtil.typeClassification(dtnm);//特征类型
        BDMS_FBC_GRID_F bdmsFbcGridF = bdms_fbc_grid_fService.getInfo(CSCHEMEID,dtnm);
        ResultData resultData = bdms_fbc_result_aService
                .GetDateByGrid(bdmsFbcGridF.getDttp(),bdmsFbcGridF.getCschemeid(),StartTime,EndTime,bdmsFbcGridF.getGridid(),
                        rule,bdmsFbcGridF.getTypeofpier(),bdmsFbcGridF.getNumber(),bdmsFbcGridF.getDtnm());
        if (resultData != null) {
            jsonResult.setStatusCode(200);
            jsonResult.setSucceeded(true);
            jsonResult.setData(resultData);
            return jsonResult;
        }else {
            jsonResult.setStatusCode(200);
            jsonResult.setSucceeded(true);
            jsonResult.setData(null);
            return jsonResult;
        }
    }
    @ApiOperation("获取港珠澳大桥全部计算结果")//港珠澳大桥
    @RequestMapping(value = "StormSurge/Calculate/GetCalculationResults",headers = "Accept=application/json",method = RequestMethod.GET)
    public JsonResult getCalculationResults(@RequestParam(value = "CSCHEMEID")String CSCHEMEID,
                                            @RequestParam("StartTime")String StartTime,//开始时间
                                            @RequestParam("EndTime")String EndTime,//结束时间
                                            @RequestParam("rule")boolean rule){//模式：true波流 false水流
        JsonResult jsonResult = new JsonResult();
        // String dttp = JudgeUtil.typeClassification(dtnm);//特征类型
        List<BDMS_FBC_GRID_F> bdms_fbc_grid_fList = bdms_fbc_grid_fService.getBasicInfo(CSCHEMEID);
        List<ResultData> resultDataList = new ArrayList<>();
        for (BDMS_FBC_GRID_F bdms_fbc_grid_f : bdms_fbc_grid_fList) {
            ResultData resultData = bdms_fbc_result_aService.GetDateByGrid(bdms_fbc_grid_f.getDttp(),
                    bdms_fbc_grid_f.getCschemeid(), StartTime, EndTime, bdms_fbc_grid_f.getGridid(), rule,
                    bdms_fbc_grid_f.getTypeofpier(), bdms_fbc_grid_f.getNumber(),bdms_fbc_grid_f.getDtnm());
            resultDataList.add(resultData);
        }
        if (resultDataList.size() > 0) {
            jsonResult.setStatusCode(200);
            jsonResult.setSucceeded(true);
            jsonResult.setData(resultDataList);
            return jsonResult;
        }else {
            jsonResult.setStatusCode(200);
            jsonResult.setSucceeded(true);
            jsonResult.setData(null);
            return jsonResult;
        }
    }

    //GetCalResultsBySeaWall
    @ApiOperation("获取海堤前沿计算结果")
    @RequestMapping(value = "StormSurge/Calculate/GetCalResultsBySeaWall", headers = "Accept=application/json", method = RequestMethod.GET)
    public JsonResult getCalResultsBySeaWall(@RequestParam String CalSchemeId,
                                             @RequestParam Integer SeaWallId) throws ParseException {
        JsonResult jsonResult = new JsonResult();

        com.jhhc.StormSurgeForecast.StormSurge.Pojo.SeaWall s= getTyphoonUitl.getCalResultsBySeaWall(CalSchemeId,SeaWallId);

        if ( s!=null){
            jsonResult.setStatusCode(200);
            jsonResult.setSucceeded(true);
            jsonResult.setData(s);
        }else {
            jsonResult.setStatusCode(200);
            jsonResult.setSucceeded(true);
            jsonResult.setData("数据为空 出现异常");
        }
        return jsonResult;
    }
    @ApiOperation("获取多个计算方案信息下的海堤前沿计算结果")
    @RequestMapping(value = "StormSurge/Calculate/GetCalResultsBySeaWalls", headers = "Accept=application/json", method = RequestMethod.GET)
    public JsonResult getCalResultsBySeaWalls(@RequestParam List<String> CalSchemeIds,
                                             @RequestParam Integer SeaWallId) throws ParseException {
        JsonResult jsonResult = new JsonResult();

        List<com.jhhc.StormSurgeForecast.StormSurge.Pojo.SeaWall >s= getTyphoonUitl.getCalResultsBySeaWalls(CalSchemeIds,SeaWallId);

        if ( s!=null){
            jsonResult.setStatusCode(200);
            jsonResult.setSucceeded(true);
            jsonResult.setData(s);
        }else {
            jsonResult.setStatusCode(200);
            jsonResult.setSucceeded(true);
            jsonResult.setData("数据为空 出现异常");
        }
        return jsonResult;
    }
    //获取越浪计算结果
    @ApiOperation("获取越浪计算结果")
    @RequestMapping(value = "StormSurge/Calculate/GetCalResultsByBank", headers = "Accept=application/json", method = RequestMethod.GET)
    public JsonResult getCalResultsByBank(@RequestParam String CalSchemeId,
                                          @RequestParam(required = false) String SeaWallId) {
        JsonResult jsonResult = new JsonResult();
        List<SeaWall> seaWalls = bdms_fbc_result_sService.selectAll(CalSchemeId,SeaWallId);
        if (seaWalls == null) {
            jsonResult.setStatusCode(200);
            jsonResult.setSucceeded(true);
            jsonResult.setData(null);
        }else {
            jsonResult.setStatusCode(200);
            jsonResult.setSucceeded(true);
            jsonResult.setData(seaWalls);
        }
        return jsonResult;
    }
    //获取养殖网箱预警状态
    @ApiOperation("获取养殖网箱预警状态")
    @RequestMapping(value = "StormSurge/Calculate/GetCageAlertStatus", headers = "Accept=application/json", method = RequestMethod.GET)
    public JsonResult getCageAlertStatus(@RequestParam String PID,
                                         @RequestParam(required = false) List<String> CageIds) {
        JsonResult jsonResult = new JsonResult();
        jsonResult.setStatusCode(200);
        jsonResult.setSucceeded(true);
        jsonResult.setData(null);
        return jsonResult;
    }
    //获取预报场的计算结果
    @ApiOperation("获取台风浪计算结果")
    @RequestMapping(value = "StormSurge/Calculate/GetCalResultsByWave", headers = "Accept=application/json", method = RequestMethod.GET)
    public JsonResult getCalResultsByWave(@RequestParam String CalSchemeId) {
        JsonResult jsonResult = new JsonResult();
        jsonResult.setStatusCode(200);
        jsonResult.setSucceeded(true);
        jsonResult.setData(null);
        return jsonResult;
    }

    //获取预报站点特征数据
    @ApiOperation("获取预报站点特征数据")
    @RequestMapping(value = "StormSurge/GetCharacteristicByStation", headers = "Accept=application/json", method = RequestMethod.GET)
    public JsonResult getCharacteristicByStation(@RequestParam String CalSchemeId, @RequestParam(required = false) List<String> StationCodes) throws IOException, ParseException {
        JsonResult jsonResult = new JsonResult();
        jsonResult.setStatusCode(200);
        jsonResult.setSucceeded(true);
        jsonResult.setData(getTyphoonUitl.getCharacteristicByStation(CalSchemeId,StationCodes));
        return jsonResult;
    }
    //GetCharacteristicBySeaWall
    @ApiOperation("获取海堤前沿特征数据")
    @RequestMapping(value = "StormSurge/Calculate/GetCharacteristicBySeaWall", headers = "Accept=application/json", method = RequestMethod.GET)
    public JsonResult getCharacteristicBySeaWall(@RequestParam String CalSchemeId,
                                                 @RequestParam(required = false) List<Integer> SeaWallIds){
        JsonResult jsonResult = new JsonResult();

        try {
            List<Characteristic> characteristics  = getTyphoonUitl.getCharacteristicBySeaWall(CalSchemeId,SeaWallIds);
            jsonResult.setStatusCode(200);
            jsonResult.setSucceeded(true);
            if(characteristics.size()>0){
                jsonResult.setData(characteristics);
            }else {
                jsonResult.setRemark("数据为空");
            }
        }catch (Exception e){
            e.printStackTrace();
            jsonResult.setStatusCode(500);
            jsonResult.setSucceeded(false);
            jsonResult.setRemark("出现异常");
        }

        return jsonResult;
    }
    //保存计算方案
    @ApiOperation("保存计算方案信息")
    @RequestMapping(value = "StormSurge/Calculate/SaveCalSchemeInfo", headers = "Accept=application/json", method = RequestMethod.GET)
    public JsonResult saveCalSchemeInfo(@RequestParam String CalSchemeId,@RequestParam(required = false) String CalSchemeName,@RequestParam
                                        String Description) {
        JsonResult jsonResult = new JsonResult();
        BDMS_CALCULATESCHEME_M1 bdms_calculatescheme_m = bdms_calculatescheme_mService.selcalSchemeId(CalSchemeId);
        bdms_calculatescheme_m.setCschemenm(CalSchemeName);
        bdms_calculatescheme_m.setFlag("y");
        bdms_calculatescheme_m.setRemark(Description);
        int res = bdms_calculatescheme_mService.saveCalSchemeInfo(bdms_calculatescheme_m);
        System.out.println(res);
        if (res>0){
            jsonResult.setStatusCode(200);
            jsonResult.setSucceeded(true);
            jsonResult.setData("计算方案信息保存成功");
        }
        return  jsonResult;
    }
    //保存计算方案
    @ApiOperation("获取已保存计算方案信息")
    @RequestMapping(value = "StormSurge/Calculate/GetSaveCalSchemeInfo", headers = "Accept=application/json", method = RequestMethod.GET)
    public JsonResult getSaveCalSchemeInfo(@RequestParam(required = false) String CalSchemeId) {
        JsonResult jsonResult = new JsonResult();
        List<BDMS_CALCULATESCHEME_M1> bdms_calculatescheme_ms = bdms_calculatescheme_mService.selectShcemeFlagByCalID(CalSchemeId);
        List<CalSchemeInfo> calSchemeInfos = new ArrayList<>();
        for (BDMS_CALCULATESCHEME_M1 bdms_calculatescheme_m:bdms_calculatescheme_ms){
            CalSchemeInfo calSchemeInfo  =new CalSchemeInfo();
            if (bdms_calculatescheme_m != null) {
                if (bdms_calculatescheme_m.getParams()!=null){
                    String [] a;
                    a= bdms_calculatescheme_m.getParams().split(",");
                    calSchemeInfo.setTyphoonId(a[0]);
                    calSchemeInfo.setTyphoonDepart(a[1]);
                    calSchemeInfo.setModelPar(df.format(Double.valueOf(a[2])));
                }
                calSchemeInfo.setCalSchemeId(bdms_calculatescheme_m.getCschemeid());
                calSchemeInfo.setUserId(bdms_calculatescheme_m.getUserid());
                //根据modelid获取model名称
                BDMS_FBC_OCEANMODEL_B bdms_fbc_oceanmodel_b =bdms_fbc_oceanmodel_bService.getModelInfoByModelId(bdms_calculatescheme_m.getPid(),bdms_calculatescheme_m.getMdid());
                if (bdms_fbc_oceanmodel_b!=null){
                    calSchemeInfo.setModelId(bdms_fbc_oceanmodel_b.getModelid());
                    calSchemeInfo.setModelName(bdms_fbc_oceanmodel_b.getModelnm());
                }
                calSchemeInfo.setForecastOperateTime(bdms_calculatescheme_m.getDtmcalculate());
                calSchemeInfo.setForecastEndTime(bdms_calculatescheme_m.getDtmend());
                calSchemeInfo.setUserName("预报员");
                calSchemeInfo.setForecastTime(bdms_calculatescheme_m.getDtmforecast());
                calSchemeInfo.setState(String.valueOf(bdms_calculatescheme_m.getState()));
                calSchemeInfo.setHasGen(bdms_calculatescheme_m.getIsgen());
                calSchemeInfo.setState(bdms_calculatescheme_m.getState());
                calSchemeInfo.setRemark("state 0 新建方案、1 计算中、2 计算失败、3 计算成功");
            }
            calSchemeInfos.add(calSchemeInfo);
        }
        jsonResult.setStatusCode(200);
        jsonResult.setSucceeded(true);
        jsonResult.setData(calSchemeInfos);
        return  jsonResult;
    }
    //获取预报精度评定
    @ApiOperation("获取预报精度评定")
    @RequestMapping(value = "StormSurge/Calculate/AccuracyEvaluation", headers = "Accept=application/json", method = RequestMethod.POST)
    public JsonResult GetForecastDifference(@RequestBody JSONObject jsonObject) throws IOException, ParseException {
        JsonResult jsonResult = new JsonResult();
        //String  calSchemeId = jsonObject.getString("calSchemeId");
        List<String> calSchemeIds = jsonObject.getList("calSchemeIds",String.class);
        jsonResult.setStatusCode(200);
        jsonResult.setSucceeded(true);
//        accuracyEvaluations
//        getTyphoonUitl.getForecastDifference(calSchemeIds);
        jsonResult.setData( getTyphoonUitl.getForecastDifference(calSchemeIds));

        System.out.println("请求结束");
        return  jsonResult;
    }
    //获取预报产品类型
    @ApiOperation("获取预报产品类型")
    @RequestMapping(value = "StormSurge/Calculate/GetProductType", headers = "Accept=application/json", method = RequestMethod.POST)
    public JsonResult GetProductType(@RequestBody JSONObject jsonObject) {

        JsonResult jsonResult = new JsonResult();
        Integer  projectId = jsonObject.getInteger("projectId");
        jsonResult.setStatusCode(200);
        jsonResult.setSucceeded(true);
        List<ProductInfoResult>  productInfoResults = getTyphoonUitl.getProductType(projectId);
        if (getTyphoonUitl.getProductType(projectId)!=null&&getTyphoonUitl.getProductType(projectId).size()>0){
            jsonResult.setData( productInfoResults);
            jsonResult.setRemark("请求成功");
        }else {
            jsonResult.setRemark("未查询到对应信息");
        }

        return jsonResult;
    }
    //获取产品方案集
    @ApiOperation("获取产品方案集")
    @RequestMapping(value = "StormSurge/Calculate/GetProductPrograms", headers = "Accept=application/json", method = RequestMethod.POST)
    public JsonResult GetProductPrograms(@RequestBody JSONObject jsonObject) {
        JsonResult jsonResult = new JsonResult();
        Integer  projectId = jsonObject.getInteger("projectId");
        String  infoId = jsonObject.getString("infoId");
        Integer  typhoonId = jsonObject.getInteger("typhoonId");
        jsonResult.setStatusCode(200);
        jsonResult.setSucceeded(true);

        jsonResult.setData(getTyphoonUitl.getProductPrograms(projectId,infoId,typhoonId));
        return jsonResult;
    }

    //获取预报产品类型
    @ApiOperation("获取报表预报成果")
    @RequestMapping(value = "StormSurge/Calculate/GetForecastResult", headers = "Accept=application/json", method = RequestMethod.POST)
    public JsonResult GetForecastResult(@RequestBody JSONObject jsonObject) {

        JsonResult jsonResult = new JsonResult();
        Integer  projectId = jsonObject.getInteger("projectId");
        String  infoId = jsonObject.getString("infoId");
        String productId=jsonObject.getString("productId");
        jsonResult.setStatusCode(200);
        jsonResult.setSucceeded(true);
        try {
            jsonResult.setData( getTyphoonUitl.getForecastResult(projectId,infoId, productId));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return jsonResult;
    }

    @ApiOperation("生成报表文档")
    @RequestMapping(value = "StormSurge/Calculate/GetSpecialReport", headers = "Accept=application/json", method = RequestMethod.POST)
    public JsonResult GetSpecialReport(@RequestBody JSONObject jsonObject) throws Exception {

        JsonResult jsonResult = new JsonResult();
        String  calSchemeId = jsonObject.getString("calSchemeId");
        List<String>  infoIds = jsonObject.getList("infoIds",String.class);
        jsonResult.setStatusCode(200);
        jsonResult.setSucceeded(true);
        jsonResult.setData( getTyphoonUitl.GetSpecialReport(calSchemeId,infoIds));
        return jsonResult;
    }


    //生成报表图片 photoServer
    @ApiOperation("生成报表图片")
    @RequestMapping(value = "StormSurge/Calculate/GenPhoto", headers = "Accept=application/json", method = RequestMethod.GET)
    public JsonResult GenPhoto(
                               @RequestParam String calSchemeId) {

        JsonResult jsonResult = getTyphoonUitl.photoServer(calSchemeId);




        return jsonResult;
    }
    //生成报表图片 photoServer
    @ApiOperation("获取报表图片")
    @RequestMapping(value = "StormSurge/Calculate/GetForecastPhoto", headers = "Accept=application/json", method = RequestMethod.GET)
    public JsonResult GetForecastPhoto(@RequestParam String calSchemeId) throws Exception {

        JsonResult jsonResult = getTyphoonUitl.readImage(calSchemeId);




        return jsonResult;
    }
//    @ApiOperation("生成水文站潮位研判文档")
//    @RequestMapping(value = "StormSurge/Calculate/GetNBSpecialReport", headers = "Accept=application/json", method = RequestMethod.POST)
//    public JsonResult GenNBSpecialReport(@RequestBody JSONObject jsonObject) throws Exception {
//
//        JsonResult jsonResult = new JsonResult();
//        String  calSchemeId = jsonObject.getString("calSchemeId");
//        String  infoId = jsonObject.getString("infoId");
//        jsonResult.setStatusCode(200);
//        jsonResult.setSucceeded(true);
//        String res = getTyphoonUitl.GenSpecialReportNB(calSchemeId,infoId);
//        if (res==null){
//            jsonResult.setRemark("未查到相关数据");
//        }else{
//            jsonResult.setData( res);
//            jsonResult.setRemark("请求成功");
//        }
//        return jsonResult;
//    }
//    @ApiOperation("生成风暴潮预报汇总文档")
//    @RequestMapping(value = "StormSurge/Calculate/GetSummaryOfStormSurgeForecast", headers = "Accept=application/json", method = RequestMethod.POST)
//    public JsonResult GetSummaryOfStormSurgeForecast(@RequestBody JSONObject jsonObject) throws Exception {
//
//        JsonResult jsonResult = new JsonResult();
//        String  calSchemeId = jsonObject.getString("calSchemeId");
//        String  infoId = jsonObject.getString("infoId");
//        jsonResult.setStatusCode(200);
//        jsonResult.setSucceeded(true);
//        jsonResult.setData(getTyphoonUitl.GetSummaryOfStormSurgeForecast(calSchemeId,infoId, getDataUtil.genChartData(calSchemeId)));
//        //jsonResult.setData(getDataUtil.genChartData(calSchemeId));
//        return jsonResult;
//    }



    @ApiOperation("修正预报数据")
    @RequestMapping(value = "StormSurge/Calculate/UpdateReportData", headers = "Accept=application/json", method = RequestMethod.POST)
    public JsonResult UpdateReportData(@RequestBody UpdateTideDataParam updateTideDataParam) {

        JsonResult jsonResult = new JsonResult();

        String  calSchemeId = updateTideDataParam.getCalSchemeId();
        String  stationCode = updateTideDataParam.getStationCode();
        String  updateValue = updateTideDataParam.getUpdateValue();

        jsonResult = getTyphoonUitl.updateData(calSchemeId,stationCode,updateValue);

        return jsonResult;
    }




    //获取智能平台预报结果
//    @ApiOperation("智能平台预报驱动")
//    @RequestMapping(value = "StormSurge/Calculate/IntelligentForecast", headers = "Accept=application/json", method = RequestMethod.POST)
//    public JsonResult IntelligentForecast (@RequestBody JSONObject jsonObject) throws Exception {
//        JsonResult jsonResult = new JsonResult();
//        //输入预报时间点  预报站
//        int  projectId = jsonObject.getInteger("projectId");
//        String tfid = jsonObject.getString("tfid");
//        double xiShu = jsonObject.getDouble("xiShu");
//        String userId = jsonObject.getString("userId");
//        String typhoonDepart =jsonObject.getString("typhoonDepart");
//        boolean isArea = jsonObject.getBooleanValue("isArea");
//        String forecastTime = jsonObject.getString("forecastTime");
//        String modelId = jsonObject.getString("modelId");
//        String modelType = jsonObject.getString("modelType");
////        if ("2".equals(modelType)){
////            //天文潮矫正值
////
////        }else if ("1".equals(modelType)){
////            //增水以及预报风暴潮位
////
////
////        }
//       // List<String> stationCodes = jsonObject.getList("stationCodes",String.class);
//        jsonResult.setStatusCode(200);
//        jsonResult.setSucceeded(true);
//        // jsonResult.setData(getTyphoonUitl.intelligentForecast(projectId,tfid,forecastTime,modelId,typhoonDepart,xiShu,modelType));
//        return  jsonResult;
//    }
    //    @ApiOperation("获取预报站点预报计算结果文件读取")
//    @RequestMapping(value = "StormSurge/Calculate/GetCalResultsByFiles", headers = "Accept=application/json", method = RequestMethod.POST)
//    public JsonResult getCalResultsByFiles(@RequestBody Param param) throws Exception {
//        JsonResult jsonResult = new JsonResult();
//        jsonResult.setStatusCode(200);
//        jsonResult.setSucceeded(true);
//        String pathData61 = path + File.separator + param.getCalSchemeId() + File.separator + "fort.61";
//        BDMS_FBC_OCEANMODEL_B b = bdms_fbc_oceanmodel_bService.selectByPid();
//        String[] sations = b.getOutpointinfo().split(",");
//        if (param.getCalSchemeId() != null && !"".equals(param.getCalSchemeId())) {
//            BDMS_CALCULATESCHEME_M1 m = m1Service.selectShcemeByCalID(param.getCalSchemeId());
//            if (m != null) {
//                int params = Integer.parseInt(m.getParams().split(",")[0]);
//                List<CalResults> calResults = null;
//                if (param.isSaveInDB()) {
//                    for (int i = 0; i < 1; i++) {
//                        pService.insertBath(pathData61, param.getCalSchemeId(),sations);
//                    }
//                    if ("1".equals(m.getIsarea())) {
//                        for (int i = 0; i < 1; i++) {
//                            String pathData63 = path + File.separator + param.getCalSchemeId() + File.separator + "fort.63";
//                            String pathData64 = path + File.separator + param.getCalSchemeId() + File.separator + "fort.64";
//                            bdms_fbc_result_aService.insertCalResultByCSDomain(pathData63,pathData64,
//                                    m.getDtmforecast(), param.getCalSchemeId(),"浙江");
//                        }
//                    }
//                    return jsonResult;
//                }else {
//                    if (param.getStationCodes() != null && param.getStationCodes().length != 0) {
//                        calResults = ReadUtil.readFors61(param.getCalSchemeId(),pathData61,
//                                m.getDtmforecast(), param.getStationCodes(),sations,params);
//                        jsonResult.setData(calResults);
//                        return jsonResult;
//                    }else {
//                        calResults = ReadUtil.readFors61(param.getCalSchemeId(),pathData61,
//                                m.getDtmforecast(),sations,params);
//                        jsonResult.setData(calResults);
//                        return jsonResult;
//                    }
//                }
//            }else {
//                jsonResult.setData("查询计算方案失败");
//                return jsonResult;
//            }
//        }else {
//            jsonResult.setData("计算方案错误");
//            return jsonResult;
//        }
//    }


}
